{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[ 0.69820199, -0.61728135,  0.95909549,  0.15330305],\n",
       "       [-1.17493431, -0.72841997,  0.76708643, -0.14680456],\n",
       "       [ 0.01043793,  0.86993666, -0.02491762,  0.01387655],\n",
       "       [ 0.50860412, -1.35704994, -1.98855612, -1.6683405 ],\n",
       "       [ 0.35890589, -1.40594323,  0.96319198,  0.60559583],\n",
       "       [ 1.27095727, -0.47456865,  0.01378142,  1.28370118],\n",
       "       [ 0.82856129, -1.59965755,  0.93742737, -1.81043601]])"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import numpy as np\n",
    "names = np.array(['Ben','Tom','Ben','Jeremy','Jeremy','Tom','Ben'])\n",
    "\n",
    "data = np.random.randn(7,4)\n",
    "data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[[ 0.50860412 -1.35704994 -1.98855612 -1.6683405 ]\n",
      " [-1.17493431 -0.72841997  0.76708643 -0.14680456]\n",
      " [ 0.01043793  0.86993666 -0.02491762  0.01387655]]\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "array([[ 0.50860412, -1.35704994, -1.98855612, -1.6683405 ],\n",
       "       [ 0.01043793,  0.86993666, -0.02491762,  0.01387655],\n",
       "       [-1.17493431, -0.72841997,  0.76708643, -0.14680456]])"
      ]
     },
     "execution_count": 21,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "print(data[[3,1,2]])\n",
    "data[[3,1,2]][[0,2,1]]"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 传入多组索引序列\n",
    "- 最终选取出三个元素，其在data数组中的位置分别是（3, 0）、（1, 2）、（2, 1）"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([0.50860412, 0.76708643, 0.86993666])"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data[[3,1,2],[0,2,1]]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[ 0.50860412, -1.35704994, -1.98855612, -1.6683405 ],\n",
       "       [-1.17493431, -0.72841997,  0.76708643, -0.14680456]])"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data[[3,1]]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[ 0.50860412, -1.35704994, -1.98855612, -1.6683405 ],\n",
       "       [-1.17493431, -0.72841997,  0.76708643, -0.14680456],\n",
       "       [ 0.01043793,  0.86993666, -0.02491762,  0.01387655]])"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data[[3,1,2]]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[ 0.69820199, -0.61728135,  0.95909549,  0.15330305],\n",
       "       [ 0.01043793,  0.86993666, -0.02491762,  0.01387655],\n",
       "       [ 0.82856129, -1.59965755,  0.93742737, -1.81043601]])"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data[ names == \"Ben\"]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[ True, False,  True,  True],\n",
       "       [False, False,  True, False],\n",
       "       [ True,  True, False,  True],\n",
       "       [ True, False, False, False],\n",
       "       [ True, False,  True,  True],\n",
       "       [ True, False,  True,  True],\n",
       "       [ True, False,  True, False]])"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data > 0"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array(['Jeremy', 'Jeremy', 'Ben', 'Tom'], dtype='<U6')"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "names[[4,3,2,1]]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array(['Ben', 'Tom', 'Jeremy', 'Jeremy'], dtype='<U6')"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "names[[-1,-2,-3,-4]]"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.8"
  },
  "orig_nbformat": 4,
  "vscode": {
   "interpreter": {
    "hash": "6fff98fc3b3d81bd655c2cc48858186e4d9e2db7b515bf1c3221888f12a62f87"
   }
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
